package praktikumid.p02_k;

/**
 * @author ago.luberg
 *
 */
public class Variables {
	/**
	 * PLAY option.
	 */
	static final int PLAY = 1;
	/**
	 * LOAD option.
	 */
	static final int LOAD = 2;
	/**
	 * SAVE option.
	 */
	static final int SAVE = 3;
	/**
	 * EXIT option.
	 */
	static final int EXIT = 4;
	/**
	 * @param args Arguments
	 */
	public static void main(String[] args) {
		int n = 5;
		// n = 5
		n = 3;
		// n = 3
		n = n + 2;
		// n = 5
		System.out.println(n / 2);
		
		float f = 5;
		System.out.println(f);
		
		String s = "hello";
		System.out.println(s + "!");
		System.out.println(s + n); //s + "5"
		
		// if (!0) C-s : if (true) javas
		// if (0) C-s : if (false) javas
		// if (n) C-s : if (n != 0) javas
		if (n > 3) {
			// kui kehtib
			System.out.println("n on suurem kui 3");
		} else {
			System.out.println("n on väiksem-võrdne kui 3");
			// kui ei kehti
		}
		
		/*
		 * 1. play
		 * 2. save
		 * 3. load
		 * 4. exit (kõik muu on exit)
		 */
		n = PLAY;
		if (n == PLAY) {
			System.out.println("let's play");
			n = 2;
		} else if (n == SAVE) {
			System.out.println("game saved");
		} else if (n == LOAD) {
			System.out.println("game loaded");
		} else {
			System.out.println("bye!");
		}
		
		// switch
		switch (n) {
		case PLAY:
			System.out.println("let's play");
			break;
			// seda ei käivitata
		case SAVE:
			System.out.println("let's save");
			break;
		case LOAD:
			System.out.println("let's load");
			break;
		default:
			System.out.println("bye!");
			break;
		}
		
		// string comparison
		String s1 = "hello";
		String s2 = s1 + "";
		System.out.println(s1); // hello
		System.out.println(s2); // hello
		
		
		// MITTE KASUTADA!
		if (s1 == s2) { // false
			System.out.println("on samad");
		} else {
			System.out.println("ei ole samad");
		}
		if (s1.equals(s2)) { // true, kontrollib sisu
			System.out.println("on sama väärtus");
		} else {
			System.out.println("ei ole sama väärtus");
		}
		
		// loops
		
		// while
		
		int i = 10;
		while (true) {
			System.out.println(i);
			System.out.println("please stop");
			i = i - 1;
			if (i <= 0) {
				break;
			}
		}
		
		i = 10;
		while (i > 0) {
			System.out.println(i);
			System.out.println("please stop");
			i = i - 1;
		}
		
		// for
		// i-- <==> i = i - 1
		for (i = 10; i > 0; i--) {
			System.out.println(i);
			System.out.println("please stop");			
		}
		
		/*
		// while (true)
		for ( ; ; ) {
			System.out.println("please stop");
		}
		*/
		
		i = 10;
		// while (i > 0)
		for ( ; i > 0; ) {
			System.out.println(i);
			System.out.println("please stop");
			i = i - 1;
		}
		
		// korrutustabel
		int j;
		for (i = 1; i <= 10; i++) {
			System.out.printf("%1$3s", i);
			for (j = 1; j <= 10; j++) {
				//
				System.out.printf("%1$3s", i * j);
			}
			System.out.println();
		}
		
	}

}